/* sonicRange

This Example demonstrates the use of the sonicRange object library

*/


#include <NewSoftSerial.h>
#include <sonicRange.h>

#define TX_PIN 12
#define RX_PIN 11

/*********************************************************************
*********************************************************************
/ Soft Serial Port and GPS object
***********************************************************************/

NewSoftSerial sx_port(RX_PIN, TX_PIN, true);

// LV-MaxSonar-EZx inverts the Serial Signal

// Comment out above and uncomment below if inverter is used on output
//NewSoftSerial sx_port(RX_PIN, TX_PIN);

sonicRange sx(sx_port);

int range;

void setup() {
  // Set ports

  // Initialize serial communication 
  Serial.begin(9600);
  // set the data rate for the SoftwareSerial port
  sx_port.begin(9600);
}

void loop() {
  
  if (sx.available()) {
    range = sx.range;
  }
  
  if (Serial.available()) {
    char inChar = Serial.read();
    Serial.print("Range = ");
    Serial.println(range);
  }
}
